BUILD-11310 Add report-ci-metrics action#298
Conversation
Agentic Analysis: Early ResultsAgentic Analysis and Context Augmentation are available on your project. Here are some issues that could have been prevented. Follow the links to learn how to put them into action. 3 issue(s) found across 1 file(s):
Analyzed by SonarQube Agentic Analysis in 3.5 s |
580e5ca to
b6f8dfe
Compare
Author-influenced values (job name, cache key, backend) recovered via jq -r could carry embedded newlines or HTML (e.g. </details>) that break the markdown table or inject markup into the write-scoped sticky comment. Centralize cell sanitization in _rci_md_cell: escape pipes, collapse CR/LF, and neutralize angle brackets. Addresses Gitar review finding on PR #298.
Collapse four multi-line shell constructs onto single physical lines so kcov attributes their execution correctly, eliminating line-attribution artifacts that showed continuation lines as uncovered. Behavior is unchanged and all 34 shellspec tests remain green. - collect_job_metrics: join gh api --paginate -q onto one line - _rci_cpu_cell: collapse the multi-line jq program to a single filter - render_cache_fold: build the cache row with a $'\n' literal instead of an embedded newline in the assignment - upsert_comment: join gh api --paginate -q onto one line lib.sh coverage 92.74% -> 100.00% (168/168).
Author-influenced values (job name, cache key, backend) recovered via jq -r could carry embedded newlines or HTML (e.g. </details>) that break the markdown table or inject markup into the write-scoped sticky comment. Centralize cell sanitization in _rci_md_cell: escape pipes, collapse CR/LF, and neutralize angle brackets. Addresses Gitar review finding on PR #298.
… compat
In bash 4.3+, a bare & in the replacement of ${var//pat/repl} expands to the
matched text, so <//< produced '<lt;' instead of '<' on CI (bash 5.x)
while passing on local bash 3.2. Escape the & (\</\>) so the entity is
literal on all bash versions.
The action reports CI metrics (CPU/memory/disk/network/cache); it does not interpret them. 'metrics' matches the feature's branding (the hook's '## CI Metrics' summary) and is more honest than 'insights', which is reserved for the planned trend/AI work. Renames the dir, script, spec, and updates sonar.sources + the kcov include-pattern.
Consolidate the action's documentation into the root README's 'Actions
provided' section, matching every other action in the repo (no sub-folder
READMEs elsewhere). Drop the separate report-ci-metrics/README.md. Also
reword the fail-open note ('the workflow' per review).
Follow-up to the README move: the previous commit only captured the sub-folder README deletion (root edits were left unstaged by the pre-commit stash). This adds the consolidated section + actions-list entry.
86a2283 to
6261c54
Compare
|
Code Review ✅ Approved 2 resolved / 2 findingsIntroduces the ✅ 2 resolved✅ Security: Rendered metric fields escape only pipes, not newlines/HTML
✅ Security: Markdown link/image syntax not neutralized in table cells
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |



What
New
report-ci-metricscomposite action (M4.3). A repository adds it as one dedicated job; it aggregates per-job CI metrics across the workflow run and posts a single sticky PR comment with a compact headline over folded detail.Ticket: BUILD-11310 · Epic: BUILD-11068
Tested in https://github.com/SonarSource/sonar-dummy/pull/619
How it gets the data (the interesting part)
Both "obvious" transports were empirically ruled out: the hook can't upload an artifact (no runtime token in the hook env — BUILD-11309), and job summaries aren't readable cross-job via any token API. The working transport: the report job (
needs: [all]) downloads each completed sibling's job log viaGET /repos/{r}/actions/jobs/{id}/logs(GITHUB_TOKEN+actions: read) and recovers the metrics JSON the runner hook prints to stdout, wrapped in sentinels (producer PRs: infra#422, this-repo#297). Proven end-to-end in a spike.Usage
Behaviour
<details>. Folding rules: columns with no data are dropped; the Flags column/line appears only when flags exist; the cache fold renders only when a job reported cache.::warning::+ exit 0; never fails the consumer workflow. Skips the report job itself, non-completed jobs, log-download failures, jobs without metrics, and corrupt-JSON records.